<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>选择专属门店</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/alert.js"></script>
    <link rel="stylesheet" href="css/weui.css"/>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">


    <script src="js/alert.js"></script>
</head>
<body>

<div class="weui-panel weui-panel_access">
    <div style="margin: 3%;font-size: 20px;color: #000000"><i class="fa fa-map-marker"></i> <span
            id="city-name"> 城市</span></div>

    <div id="num" class="weui-panel__hd">附近3家门店</div>

    <div class="weui-panel__bd" style="padding-left: 2%;" id="data">
        <div>
            <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__hd">
                    <img class="weui-media-box__thumb" src="images/ban03.jpg" alt="">
                </div>
                <div class="weui-media-box__bd">
                    <h4 class="weui-media-box__title">万达店</h4>
                    <p class="weui-media-box__desc">石家庄长安区中山东路谈固大街交口奥术大师大所大所多哇</p>
                </div>
            </a>
        </div>
        <div>
            <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__hd">
                    <img class="weui-media-box__thumb" src="images/ban03.jpg" alt="">
                </div>
                <div class="weui-media-box__bd">
                    <h4 class="weui-media-box__title">万达店</h4>
                    <p class="weui-media-box__desc">石家庄长安区中山东路谈固大街交口奥术大师大所大所多哇</p>
                </div>
            </a>
        </div>
        <div>
            <a href="#" class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__hd">
                    <img class="weui-media-box__thumb" src="images/ban03.jpg" alt="">
                </div>
                <div class="weui-media-box__bd">
                    <h4 class="weui-media-box__title">万达店</h4>
                    <p class="weui-media-box__desc">石家庄长安区中山东路谈固大街交口奥术大师大所大所多哇</p>
                </div>
            </a>
        </div>

        <div>
            <a href="#" class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__hd">
                    <img class="weui-media-box__thumb" src="images/ban023.jpg">
                </div>
                <div class="weui-media-box__bd">
                    <h4 class="weui-media-box__title">万达店</h4>
                    <p class="weui-media-box__desc">石家庄长安区中山东路谈固大街交口奥术大师大所大所多哇</p>
                </div>
            </a>
        </div>


    </div>

</div>

</body>
<script src="js/jquery.min.js"></script>
<script>

    $(document).ready(function () {
        data();
    });
    $('img').error(function () {
        $(this).attr('src', "img/znwu1.png");
    });

    function data() {
        $.ajax({
            "url": "/store/city/",
            "type": "POST",
            "dataType": "json",
            "success": function (json) {
                if (json.state == 200) {
                    var url = window.location.host;
                    var map = json.data;
                    $("#city-name").html(map.city);
                    $("#num").html("附近有" + map.count + "家门店");
                    $("#data").empty();
                    var empS = map.empSwitch;
                    for (var i = 0; i < map.data.length; i++) {
                        if (empS == "Y") {
                            var html = '<div>';
                        } else {
                            var html = '<div class="stored" data-id="' + map.data[i].id + '" data-name="' + map.data[i].name + '">';
                        }

                        html += '<a class="weui-media-box weui-media-box_appmsg">' +
                            '<div class="weui-media-box__hd">' +
                            '<img class="weui-media-box__thumb" src="#{img}" >' +
                            '</div>' +
                            '<div class="weui-media-box__bd">' +
                            '<h4 class="weui-media-box__title">#{store}</h4>' +
                            '<p class="weui-media-box__desc">#{address}</p>' +
                            '</div>' +
                            '</a></div>';

                        //html = html.replace("#{img}", map.data[i].img);
                        html = html.replace("#{img}", "http://" + url + ":8080/img/" + map.data[i].account + "/" + map.data[i].name + ".png");
                        html = html.replace("#{store}", map.data[i].name);
                        html = html.replace("#{address}", map.data[i].address);

                        $("#data").append(html);
                    }
                }
            }
        })
    }

    $("#data").on("click", ".stored", function () {
        var id = $(this).data("id");
        var store = $(this).data("name");

        reg(id, store)

    });

    function reg(id, store) {

        if (!confirm("确定要选择" + store + "吗？")) {
            return
        }

        $.ajax({
            "url": "/vip/register/",
            "data": "store=" + store,
            "type": "POST",
            "dataType": "json",
            "success": function (json) {
                if (json.state == 200) {
                    location.href = "user.html"
                } else {
                    alert(json.message);
                }
            }
        })
    }

</script>

</html>